Shader "Tapsan omat shaderit/2"
{
	Properties
	{
		_Color ("Väri",Color) = (1,1,1,1)
		_SpecColor("Spec color",Color)=(1,1,1,1)
		_Shininess("Shininess",Float)=1
	}
	SubShader
	{
		Pass
		{
			Tags {"LightMode" = "ForwardBase"}
			
			CGPROGRAM
				
				// kerrotaan että vert -funktio on vertexiohjelma 
				#pragma vertex vert
				// ja frag fragment -ohjelma
				#pragma fragment frag
				
				float4 _Color;
				float4 _LightColor0;
				float4 _SpecColor;
				float _Shininess;
			
				struct vertexInput
				{
					float4 vertex : POSITION;
					float3 normal : NORMAL;
				};
				
				struct vertexOutput
				{
					float4 pos : SV_POSITION;
					float4 col : COLOR;
				};
				
				// vertexiohjelma
				vertexOutput vert(vertexInput v)
				{
					vertexOutput o;
					
					float3 viewDirection = normalize(float3(float4(_WorldSpaceCameraPos.xyz,1.0)-mul(_Object2World,v.vertex).xyz));
					
					float3 normalDirection = normalize(mul(float4(v.normal,0.0), _World2Object).xyz);
					float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
					float3 diffuseReflection = _LightColor0.xyz * _Color.rgb * dot(normalDirection,lightDirection);
					
					
					float3 specularReflection = _LightColor0.xyz*max(0.0,dot(normalDirection,lightDirection))*
					pow(max(0.0,dot(reflect(-lightDirection,normalDirection),viewDirection)),_Shininess);
					
					
					float3 lightFinal = (specularReflection*_SpecColor.rgb) + diffuseReflection + UNITY_LIGHTMODEL_AMBIENT.xyz;
					
					
					
					o.col = float4(lightFinal,1.0);
					o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
					
					return o;
				}
				// pixeli/fragmenttiohjelma
				float4 frag(vertexOutput i) : COLOR
				{
					return i.col;
				}
				
			ENDCG
		}
	}
	
	FallBack "Diffuse"
}
